import { Article, Channel } from '@/types/data'
import http from '@/utils/http'
import { MyAxiosPromise } from './user'
// 获取用户频道
export function userChannels (): MyAxiosPromise<{ channels: Channel[] }> {
  return http({ url: 'user/channels', method: 'get' })
}
// 获取所有频道
export function channels (): MyAxiosPromise<{ channels: Channel[] }> {
  return http({ url: 'channels', method: 'get' })
}
// 设置用户频道
export function userChannelsPatch (id: number) {
  return http({
    url: 'user/channels',
    method: 'patch',
    data: { channels: [{ id }] }
  })
}

// 删除用户频道
export function userChannelsDelete (id: number) {
  return http({
    url: 'user/channels',
    method: 'delete',
    data: { channels: [id] }
  })
}

// 获取文章列表
export function articles (
  channel_id: number,
  timestamp: number
): MyAxiosPromise<{ pre_timestamp: string; results: Article[] }> {
  return http({
    url: 'articles',
    method: 'get',
    params: { channel_id, timestamp }
  })
}
